<template>
	<view class="">
		<view class="tab"><lrTabs :tabs="tabs" @change="change"></lrTabs></view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view v-for="(item, index) in couponList" :key="item.businessId">
					<coupon-cell
					:businessId="item.businessId"
					:discountAmount="item.money"
					:rangInfo="item.conditionMoney"
					:activityType="item.couponName"
					:durationDate="item.useTime"
					:couponType="item.businessName"
					:storeRang = "item.applicableUnit"
					:useNotice="item.useNotice"
			        :businessType="1"
					:memberCouponStatus="item.memberCouponStatus"
					:isReceive="couponBusiness == 0 ? 2 : 1"
					:useArea="item.useArea"
					:isTurn="item.isTurn"
					:memberId="item.memberId"
					:useTypeName="item.useTypeName"
					:applicableUnitType="item.applicableUnitType"
					@shareCoupon="shareCoupon"
					@getCoupon="getCoupon"
					></coupon-cell>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import lrTabs from '@/components/activity/lr-tabs.vue'
	import couponCell from '@/components/coupon/coupon-cell.vue'
	import {apiMyCouponList} from '@/api/marketing-api.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			lrTabs,
			couponCell
		},
		data() {
			return {
				tabs: [
					{
						stuta:0,
						code : '',
						value : '待使用'
					},
					{
						code : '',
						stuta:1,
						value : '已使用'
					},
					{
						code : '',
						stuta:2,
						value : '已过期'
					},
					{
						code : '',
						stuta:3,
						value : '已赠送'
					}
				],
				
				couponBusiness : 0,
				couponList: [],
				memberId: ''
			}
		},
		onLoad() {
	
		},
		methods: {
			upCallback(page) {
				apiMyCouponList({
					pageNo : page.num,
					couponBusiness : this.couponBusiness,
					memberNo : this.$store.state.user.userInfo.memberNo
				}).then(res => {
					//设置列表数据
					if (page.num == 1) this.couponList = []; //如果是第一页需手动制空列表
					this.couponList = this.couponList.concat(res.data); //追加新数据
					this.mescroll.endSuccess(res.data.length);
					
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			
			change(index) {
				let item = this.tabs[index];
				this.couponBusiness = item.stuta;
				this.mescroll.triggerDownScroll();
			},
			
			getCoupon() {
				this.mescroll.triggerDownScroll();
			}
		},
		
		
			
		shareCoupon(obj) {
			this.memberId = obj.memberId;
		},
		
		onShareAppMessage(res) {
		   var eData = res.target.dataset;
		   return {
		    title : '朋友送你优惠券快来领取了!!!!',
		    path:'/pagesB/coupon/coupon-detail?memberId=' + eData.memberid + '&type='+ '1' + '&turnMemberNo=' + this.$store.state.user.userInfo.memberNo
		   }
		},
	}
</script>

<style lang="scss" scoped>
	.tab {
		position: sticky;
		top: 0;
		background-color: #F5F5F5;
		z-index: 2;
	}
</style>
